package com.aster.common.api.service.imp;

import com.aster.common.api.dao.GeneralUserInfoDao;
import com.aster.common.api.domain.TbGeneralUserInfo;
import com.aster.common.api.service.GeneralUserInfoService;
import com.aster.common.api.service.criteria.GeneralUserInfoCriteria;
import com.aster.common.base.BaseServiceImpl;
import com.aster.common.exception.ServiceException;
import com.aster.common.utils.DateUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * <br>
 * <b>功能：</b>TbGeneralUserInfoService<br>
 */
@Service("generalUserInfoService")
public class  GeneralUserInfoServiceImpl  extends BaseServiceImpl implements GeneralUserInfoService {
  private final static Logger log = Logger.getLogger(GeneralUserInfoServiceImpl.class);
	

	@Autowired
    private GeneralUserInfoDao dao;

		
	public GeneralUserInfoDao getDao() {
		return dao;
	}


	@Override
	public TbGeneralUserInfo getUserByOpenId(String openId) {
		return getUserByPar("openId",openId);
	}

	@Override
	public TbGeneralUserInfo getUserByTel(String tel) {
		return getUserByPar("tel",tel);
	}

	@Override
	public void saveUserInfo(TbGeneralUserInfo tbGeneralUserInfo) throws ServiceException {
		try {
			tbGeneralUserInfo.setCreateTime(DateUtil.nowDateTIme());
			tbGeneralUserInfo.setUpdateTime(DateUtil.nowDateTIme());
			tbGeneralUserInfo.setState(1);
			tbGeneralUserInfo.setDeleted(1);
			super.add(tbGeneralUserInfo );
		}catch (Exception ex){
			throw new ServiceException(55555,ex.getMessage());
		}

	}


	private TbGeneralUserInfo getUserByPar(String key,String value){
		GeneralUserInfoCriteria criteria = new GeneralUserInfoCriteria();
		criteria.put(key,value);
		TbGeneralUserInfo tbGeneralUserInfo = dao.getGeneralUserInfo(criteria);
		return tbGeneralUserInfo;
	}
}
